//
//  HCMineAsksTableViewCell.m
//  HappyChildren
//
//  Created by WillyZhao on 2017/1/18.
//  Copyright © 2017年 WillyZhao. All rights reserved.
//

#import "HCMineAsksTableViewCell.h"

#import "HCAdoptTableViewCell.h"

#import "HCMineAskedModel.h"

@interface HCMineAsksTableViewCell () <UITableViewDataSource,UITableViewDelegate> {
    HCMineAskedData *cellData;
}

@end

@implementation HCMineAsksTableViewCell

- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    self.promptview.backgroundColor = YBKRGBCOLOR(242, 242, 242, 1);
    self.bgView.layer.cornerRadius = 5.0f;
    self.labelBG.backgroundColor = YBKRGBCOLOR(232, 232, 232, 1);
    self.lineView.backgroundColor = YBKRGBCOLOR(242, 242, 242, 1);
    self.labelBG.layer.cornerRadius = 3.0f;
    self.bgcontain.constant = 10;
    
    self.tableView_bottom.delegate = self;
    self.tableView_bottom.dataSource = self;
    self.tableView_bottom.scrollEnabled = NO;
    self.tableView_bottom.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView_bottom.layer.cornerRadius = 5.0f;
    
    [self.tableView_bottom registerNib:[UINib nibWithNibName:@"HCAdoptTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"adoptcell"];
    
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return cellData.answer.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HCAdoptTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"adoptcell" forIndexPath:indexPath];
    if (cellData) {
        HCMineAskedDataAnswer *answerData = cellData.answer[indexPath.row];
        cell.model = answerData;
    }
    [cell.sureBtn addTarget:self action:@selector(btnSureAction:event:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

+(CGFloat)cellHeight:(NSInteger)model {
    return 160+model*60.0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}

-(BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    return NO;
}

-(void)btnSureAction:(UIButton *)btn event:(id)event{
    NSSet *touches = [event allTouches];
    UITouch *touch = [touches anyObject];
    
    CGPoint currentTouchPosition = [touch locationInView:self.tableView_bottom];
    NSIndexPath *indexPath = [self.tableView_bottom indexPathForRowAtPoint:currentTouchPosition];
    if ([self.delegate respondsToSelector:@selector(sureBtnClicked:cellEvent:)]&&self.delegate) {
        [self.delegate sureBtnClicked:indexPath cellEvent:event];
    }
}

-(void)setCellModel:(id)cellModel {
    cellData = (HCMineAskedData *)cellModel;
    
    if (HCGETUSER(@"headPath")) {
        [self.headIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",HCGETUSER(@"headPath")]]];
    }
    
    if (HCGETUSER(@"nameUser")) {
        self.name.text = [NSString stringWithFormat:@"%@",HCGETUSER(@"nameUser")];
    }
    
    self.time.text = [NSString stringWithFormat:@"%@",cellData.time];
    self.text.text = [NSString stringWithFormat:@"%@",cellData.text];
    
    [self.reloadButton setTitle:[NSString stringWithFormat:@"回答 %@",cellData.count] forState:UIControlStateNormal];
    
    [self.tableView_bottom reloadData];
}

@end
